package com.example.springbootexamples.sort;

import org.junit.Test;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Random;

public class T {

    @Test
    public void t(){

        List<Integer> list=new ArrayList<>();
        for(int i=0;i<20;i++){
            list.add(new Random().nextInt(100));
        }

        list.sort(new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                if(o1<o2) return -1;
                return 0;
            }
        });

        System.out.println("------------");
        for (int i = 0; i < list.size(); i++) {
            System.out.println(list.get(i));
        }
        System.out.println("===============");
        try {
            for (int i = 0; i < list.size() - 1; i++) {
                System.out.println(i+"\t"+list.get(i) + "\t" + list.get(i + 1));
                if (list.get(i) > list.get(i + 1)) {
                    throw new RuntimeException("aaaaaaaaaaa");
                }

            }
        }catch (Exception e){
            e.printStackTrace();

        }



    }


    @Test
    public void t2(){
        String s="3\n" +
                "5\n" +
                "5\n" +
                "7\n" +
                "11\n" +
                "15\n" +
                "19\n" +
                "28\n" +
                "35\n" +
                "36\n" +
                "37\n" +
                "51\n" +
                "66\n" +
                "70\n" +
                "72\n" +
                "72\n" +
                "73\n" +
                "80\n" +
                "86\n" +
                "94\n" +
                "3\n" +
                "9\n" +
                "12\n" +
                "14\n" +
                "21\n" +
                "23\n" +
                "29\n" +
                "31\n" +
                "31\n" +
                "44\n" +
                "47\n" +
                "48\n" +
                "49\n" +
                "49\n" +
                "52\n" +
                "58\n" +
                "61\n" +
                "85\n" +
                "94\n" +
                "96";

        s="3\n" +
                "5\n" +
                "5\n" +
                "7\n" +
                "11\n" +
                "15\n" +
                "3\n" +
                "9\n" +
                "12\n" +
                "14\n" +
                "21";
        //System.out.println(s);
        System.out.println("===============");
        String arr[]=s.split("\n");
        List<Integer> list=new ArrayList<>();
        for(int i=0;i<arr.length;i++){
            list.add(Integer.parseInt(arr[i]));
        }
        list.sort(new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                if(o1<o2) return -1;
                return 0;
            }
        });

        for(Integer i:list){
            System.out.println(i);
        }


    }
    
    
    
    
    @Test
    public void t23(){

        String s="were&";
        if(s.endsWith("&")){
            s=s.substring(0,s.length()-1);
        }
        System.out.println(s);


    }


}
